const express = require('express');
const app = express();
// 处理post请求
const bodyParser = require('body-parser')
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: false }))
//设置允许跨域访问该服务.
app.all('*', function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Origin', 'http://localhost:8080');
  res.header("Access-control-Allow-Headers", "xCors");    //允许请求头中携带 xCors
  res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
  // res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
  // res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
  res.header('Content-Type', 'application/json;charset=utf-8');
  next();
});
// 设置静态资源的访问
app.use("/public", express.static(__dirname + "/public"));
app.use("/uploadFile", express.static(__dirname + "/uploadFile"));
// app.use("/images",express.static(__dirname+"/images"));
//导入路由文件
const indexRouter = require('./router/index')
// 使用路由
app.use('/', indexRouter)
// , 'backServe.com'
app.listen('3000', 'backServe.com', function () {
  console.log('node is serve: code-> 3000')
})
